import React from 'react';
import store from './redux';




class App extends React.Component{
  constructor(props){
    super(props);
    this.state={
      products:[
          // store.getState()
        ]
    } 
    store.subscribe(()=>{
      console.log(store.getState())
      this.setState({
        products:store.getState().products
      })
    })
  }
  addProduct(){
    store.dispatch({type:'PRODUCT',product:{id:'001',name:'🐖'}});
  }
  render(){
    return(
      <div>
       <button onClick={e=>this.addProduct()}>添加商品</button><br/>
       <ul>
         {
           this.state.products.map(item=>{
             console.log(item)
             return(
              <li key={item.id}>{item.name}</li>
             ) 
           })
         }
       </ul>

       <button>加入购物车</button>
      </div>
    )
  }
}
export default App;
